package dbConn;

import java.sql.*;

/**
 * Verzorgt de verbinding met de Database
 * @author TetraCON
 *
 */
public class DBConn {
	private Connection conn = null;
	private Statement stmnt = null;
	private String driver = "interbase.interclient.Driver";
	private String user = "SYSDBA";
	private String pass = "masterkey";
	private String dbURL = "jdbc:interbase://127.0.0.1/D:/Projects/Java/Containing/Containing/db/CONTAINER.IB";
	
	/**
	 * 
	 */
	public DBConn() {
		try {
			Class.forName(driver);
		}
		catch (ClassNotFoundException cnfe) {
			System.out.println("De driver is niet geladen!");
			cnfe.printStackTrace();
		}
	}
	
	/**
	 * Open de connectie met de Database
	 */
	public void open() {
		try {
			conn = DriverManager.getConnection(dbURL, user, pass);
			stmnt = conn.createStatement();
		} 
		catch (SQLException se) {
			System.out.println("Er is een probleem met de db opgetreden!" + se);
		}
		
	}
	
	/**
	 * Sluit de connectie met de Database
	 */
	public void close() {
		try {
			conn.close();
		} 
		catch (SQLException e) {
			e.printStackTrace();
		}	
	}
	
	/**
	 * 
	 * @param query
	 */
	public void execQuery(String query) {
		try {
			stmnt.execute(query);
		}
		catch (SQLException se) {
			System.out.println("De query kon niet worden uitgevoerd! ==> " + se);
		}		
	}
	
	/**
	 * 
	 * @param query
	 * @return Resultset
	 */
	public ResultSet execResQuery(String query) {
		try {
			return stmnt.executeQuery(query);
		}
		catch (SQLException se) {
			System.out.println("De query kon niet worden uitgevoerd!");
			return null;
		}		
	}
}
